package io.scnb.lesson001.demo3;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * demo3.beans.xml：
 * spring容器创建这两个UserModel的时候，都会通过反射的方式去调用UserModel类中对应的构造函数来创建UserModel对象。
 */
public class Client {

    public static void main(String[] args) {
        String beanXml = "classpath:/io/scnb/lesson001/demo3/beans.xml";

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);

        System.out.println("Spring容器中所有bean如下:");
        // getBeanDefinitionNames用于获取容器中所有Bean的名称
        for (String beanName : context.getBeanDefinitionNames()) {
            System.out.println(beanName + ": " + context.getBean(beanName));
        }

        System.out.println("================");
        // 多次获取createByFactoryBean看看是否是同一个对象
        System.out.println("createByFactoryBean:" + context.getBean("createByFactoryBean"));
        System.out.println("createByFactoryBean:" + context.getBean("createByFactoryBean"));
    }
}
